/**
 * 
 */
var oldPasswordFlag=0;
var strengthFlag=0;
var confirmFlag=0;
//$(document).ready(function(){
//	alert(xxxx);
//	alert("1");
function confirmOldPassword(){
	
//	$("#oldPassword").keyup(function(){
//	$("#oldPassword").blur(function(){
		var userName=$("#userName").val();
		var oldPassword=$("#oldPassword").val();
		var verificationResult="";
		var wrongInfo="Password Wrong!";
		var rightInfo="Password Right!";
		$.ajax({
			url : "modifyUserPassword.action?userName="+userName+"&oldPassword="+oldPassword,
			 async:false,
			 cache:false,
//			 dataType:'json',
//			 scriptCharset: 'utf-8',
//			 contentType:'application/x-www-form-urlencoded; charset=UTF-8',
			success:function(result){
//				alert("success");
//				var verification=JSON.parse(result);
				if(result==1){
//					$("#submitButton").removeAttr("disabled");
					result=rightInfo;
					oldPasswordFlag=1;
				}
				if(result==0){
//					$("#submitButton").attr("disabled","disabled");
					result=wrongInfo;
					oldPasswordFlag=0;
				}
				verificationResult+="<span>"+result+"</span>";
				$("#oldPassword").next().empty();
				$("#oldPassword").after(verificationResult);
				
			}
	    });
//	});
//	});
}
//});
	//输入完之后校验两次输入是否一致
	function KeyUp() {
		var newPassword = $('#newPassword').val();
		var confirmPassword = $('#confirmPassword').val();
		var confirmResult="";
		var sameInfo="Password is ok!";
		var differentInfo="Password is not same!";
		if (newPassword == confirmPassword) {
			confirmResult=sameInfo;
			confirmFlag=1;
		}
		else {
			confirmResult=differentInfo;
			confirmFlag=0;
		}
	    confirmResult="<span>"+confirmResult+"</span>";
		$("#confirmPassword").next().empty();
		$("#confirmPassword").after(confirmResult);
	}

	//密码规则提示
	window.onload=function(){
		var aInput=document.getElementsByTagName('input');
		var oName=aInput[0];
		var pwd=aInput[1];
		var newPwd=aInput[2];
		var aP=document.getElementsByTagName('p');
		var name_msg=aP[0];
		
		
		newPwd.onfocus=function(){
			name_msg.style.display="block";
			name_msg.innerHTML='<i class="ati"></i>数字和大小写字母与特殊字符合，即密码中应同时包含数字、大写字母、小写字母及特殊字符。'
		}
		
	}

	//密码强度相关 CharMode函数 
	//测试某个字符是属于哪一类. 
		function CharMode(iN){ 
			if (iN>=48 && iN <=57) //数字 
				return 1; 
			if (iN>=65 && iN <=90) //大写字母 
				return 2; 
			if (iN>=97 && iN <=122) //小写 
				return 4; 
			else 
				return 8; //特殊字符 
		} 
	//bitTotal函数 
	//计算出当前密码当中一共有多少种模式 
		function bitTotal(num){ 
			modes=0; 
			for (i=0;i<4;i++){ 
			if (num & 1) modes++; 
				num>>>=1; 
		} 
			return modes; 
	} 
	//checkStrong函数 
	//返回密码的强度级别 
		function checkStrong(sPW){ 
			if (sPW.length<=4) 
				return 0; //密码太短 
			Modes=0; 
			for (i=0;i<sPW.length;i++){ 
	//测试每一个字符的类别并统计一共有多少种模式. 
			Modes|=CharMode(sPW.charCodeAt(i)); 
			} 
			return bitTotal(Modes); 
		} 
	//pwStrength函数 
	//当用户放开键盘或密码输入框失去焦点时,根据不同的级别显示不同的颜色 
//		alert(xxxx);
		function pwStrength(pwd){
			confirmFlag=0;
//			alert("pwStrength:");
			O_color="#53e3a6"; 
			L_color="#FF0000"; 
			M_color="#FF9900"; 
			H_color="#33CC00"; 
		if (pwd==null||pwd==''){ 
			Lcolor=Mcolor=Hcolor=O_color; 
		} 
		else{ 
			S_level=checkStrong(pwd); 
			switch(S_level) { 
				case 0: 
			Lcolor=Mcolor=Hcolor=O_color; 
				case 1: 
			Lcolor=L_color; 
			Mcolor=Hcolor=O_color; 
				break; 
				case 2: 
			Lcolor=Mcolor=M_color; 
			Hcolor=O_color; 
				break; 
				default: 
			Lcolor=Mcolor=Hcolor=H_color; 
			} 
		} 
		document.getElementById("strength_L").style.background=Lcolor; 
		document.getElementById("strength_M").style.background=Mcolor; 
		document.getElementById("strength_H").style.background=Hcolor;
		//如果强度是弱，则不允许修改
		if(S_level==0){
//			$("#submitButton").attr("disabled","disabled");
			strengthFlag=0;
//			alert("hahahha");
		}
		if(S_level>0){
			strengthFlag=1;
			//$("#submitButton").removeAttr("disabled");
		}
			return; 
	}
		
//		var oldPasswordFlag=0;
//		var strengthFlag=0;
//		var confirmFlag=0;
		setInterval(checkFlag,200);
		function checkFlag(){
		if(oldPasswordFlag==1 && strengthFlag==1 && confirmFlag==1){
			$("#submitButton").removeAttr("disabled");
		}
		/*if(oldPasswordFlag==0 || strengthFlag==0 || confirmFlag==0){
//			alert("disabled");
			$("#submitButton").attr("disabled","disabled");
		}*/
		else{
			$("#submitButton").attr("disabled","disabled");
		}
		}
//});
